package com.example.pathprotectsystem.service.impl;

import com.example.pathprotectsystem.mapper.BindMapper;
import com.example.pathprotectsystem.pojo.*;
import com.example.pathprotectsystem.service.BindService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BindServiceImpl implements BindService {
    @Autowired
    private BindMapper bindMapper;

    @Override
    public void addtask(String taskType, String taskName, String taskTime, String status, int userid, int pathid) {
        bindMapper.addtask(taskType, taskName, taskTime,status, userid, pathid);
    }

    @Override
    public PageBean<BindModel> tasklist(AskList askList) {
        //创建PageBean对象
        PageBean<BindModel> pb = new PageBean<>();
        Integer pageNum = askList.getPageNum();
        Integer pageSize = askList.getPageSize();
        String str = askList.getStr();
        //开启分页查询 ,PageHelper是个插件
        PageHelper.startPage(pageNum,pageSize);
        List<BindModel> as = bindMapper.pathlist(str);
        as.forEach(System.out::println);
        //Page中提供了方法，可以获取PageHelper分页查询后  得到的总记录条数和当前页数据
        Page<BindModel> p = (Page<BindModel>) as;
        //把数据填充到PageBean对象中
        pb.setItems(p.getResult());
        pb.setTotal(p.getTotal());
        return pb;
    }

    @Override
    public void taskupdate(int userid, int pathid, String taskTime,int id) {
        bindMapper.taskupdate(userid,pathid,taskTime,id);
    }

    @Override
    public void taskdelete(int id) {
        bindMapper.taskdelete(id);
    }

    @Override
    public int findPathIdFromTask(int id) {
        return bindMapper.findPathIdFromTask(id);
    }

    @Override
    public int findUserIdFromTask(Integer id) {
        return bindMapper.findUserIdFromTask(id);
    }

    @Override
    public void taskupdatestatus(int id) {
        bindMapper.taskupdatestatus(id);
    }

    @Override
    public void taskfinalstatus(int id) {
        bindMapper.taskfinalstatus(id);
    }

    @Override
    public String getstatus(int id) {
        String s = bindMapper.getstatus(id);
        return s;
    }

    @Override
    public void AIaddtask(int pathid, String taskType, String taskName, String status) {
        bindMapper.AIaddtask(pathid,taskType,taskName,status);
    }

}
